using DevFramework.Entities.Concrete;
using FluentNHibernate.Mapping;

namespace DevFramework.DataLayer.Concrete.NHibernate.Mapping
{
    public class CustomerMap : ClassMap<Customer>
    {
        public CustomerMap()
        {
              Table(@"Customers");

              LazyLoad();

              Id(x => x.CustomerId)
                .Column("CustomerID")
                .CustomType("String")
                .Access.Property()
                .CustomSqlType("nchar")
                .Not.Nullable()
                .Length(5)
                .GeneratedBy.Assigned();

              Map(x => x.CompanyName)    
                .Column("CompanyName")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Not.Nullable()
                .Length(40);

              Map(x => x.ContactName)    
                .Column("ContactName")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(30);

              Map(x => x.ContactTitle)    
                .Column("ContactTitle")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(30);

              Map(x => x.Address)    
                .Column("Address")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(60);

              Map(x => x.City)    
                .Column("City")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(15);

              Map(x => x.Region)    
                .Column("Region")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(15);

              Map(x => x.PostalCode)    
                .Column("PostalCode")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(10);

              Map(x => x.Country)    
                .Column("Country")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(15);

              Map(x => x.Phone)    
                .Column("Phone")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(24);

              Map(x => x.Fax)    
                .Column("Fax")
                .CustomType("String")
                .Access.Property()
                .Generated.Never()
                .CustomSqlType("nvarchar")
                .Length(24);

              //HasMany(x => x.Orders)
              //  .Access.Property()
              //  .AsSet()
              //  .Cascade.None()
              //  .LazyLoad()
              //  // .OptimisticLock.Version() /*bug (or missing feature) in Fluent NHibernate*/
              //  .Inverse()
              //  .Generic()
              //  .KeyColumns.Add("CustomerID", mapping => mapping.Name("CustomerID")
              //                                                       .SqlType("nchar")
              //                                                       .Nullable()
              //                                                       .Length(5));
        }
    }
}
